import "babel-polyfill";
import Vue from "vue";
import App from "@/App.vue";
import router from "@/router";
import axios from "axios";
import VueAxios from 'vue-axios';
import store from "@/store";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import "bootstrap";
import "bootstrap/dist/css/bootstrap.css";
import "bootstrap/dist/js/bootstrap.min.js";
import 'jquery';
import i18n from "@/i18n/";
import Message from "@/util/Message";
Vue.prototype.$MessageAlert = Message;
import Cookie from '@/util/Cookie';
Vue.prototype.$Cookie = Cookie;
let Base64 = require('js-base64').Base64;


import { get, post, put, dele} from "@/util/http";
Vue.prototype.$get = get;
Vue.prototype.$post = post;
Vue.prototype.$put = put;
Vue.prototype.$dele = dele;

import BaiduMap from "vue-baidu-map";
Vue.use(BaiduMap, {ak: "TFCaycrhl3y93rQDpWFs15F9xIbmPgSV"});

Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.use(VueAxios, axios);

// 替换网页标题
router.beforeEach((to, from, next) => {
  if(to.meta.title) {
    document.title = to.meta.title;
  }
  next();
})

//请求拦截器
axios.interceptors.request.use(    
  config => {        
      // 每次发送请求之前判断Cookie中是否存在token        
      // 如果存在，则统一在http请求的header都加上token，这样后台根据token判断你的登录情况
      // 即使本地存在token，也有可能token是过期的，所以在响应拦截器中要对返回状态进行判断 
      if(Cookie.getCookie("token") != undefined) {
        const token = Base64.decode(Cookie.getCookie("token"));
        token && (config.headers.common["Authorization"] = "Bearer " + token);
		
      }
      return config;
  },    
  error => {        
      return Promise.error(error);
  }
);

new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount("#app");
